package com.cea.papyrustest.uml.deletecommand;

import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.InstanceSpecification;

import com.cea.papyrus.core.commands.UMLElementDeleteCommand;

/**
 * Test class for {@link InstanceSpecification} deletion command
 * @author Remi Schnekenburger
 */
public class InstanceSpecificationDeleteCommandTest extends PapyrusCommandTest{

	/** name of  the element to find */
	public static String NAME="InstanceSpecification0";
	
	/**
	 * Default constructor
	 * @param name the name of the test case
	 */
	public InstanceSpecificationDeleteCommandTest(String name) {
		super(name);	
	}

	@Override
	protected void setUp() throws Exception {
		super.setUp();
		
		// find instance specification to delete
		Element clazz=model.getPackagedElement(NAME);
		if(clazz == null || !(clazz instanceof InstanceSpecification)) {
			fail("impossible to find "+NAME);
		}
		
		papyrusCommand= new UMLElementDeleteCommand(clazz, model);
	}

	/* (non-Javadoc)
	 * @see com.cea.papyrustest.PapyrusCommandTest#testExecute()
	 */
	@Override
	public void testExecute() {
		stack.execute(papyrusCommand);
		assertNull("the instance specification still exists!",model.getPackagedElement(NAME));
		
		stack.undo();
		Element clazz=model.getPackagedElement(NAME);
		assertNotNull("the instance specification is re-created",clazz);
		assertTrue("this is not a instance specification", ((clazz)instanceof InstanceSpecification));

		stack.redo();
		assertNull("the instance specification still exists!",model.getPackagedElement(NAME));
	}
}
